#include<bits/stdc++.h>
using namespace std;
int arr[100010]={};
int n;
int check(int s,int m){
    int cnt=0;
    for(int i = 1;i<=n;i++){
        if(i==1)continue;
        else{
            for(int j = 1;j<i;j++){
                if((!(i>=s&&i<=s+m&&j>=s&&j<=s+m))||(!((i<s||i>s+m)&&(j<s||j>s+m))))continue;
                if(arr[i]==arr[j]){
                    cnt+=arr[i];
                    break;
                }
            }
        }
    }
    return cnt;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    for(int i = 0;i<t;i++){
        int maxx=-1;
        cin>>n;
        for(int j = 0;j<n;j++)cin>>arr[n];
        for(int j = 1;j<=n;j++){
            for(int k=1;k<=n-j+1;j++){
                maxx=max(check(j,k),maxx);
            }
        }
        cout<<maxx<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
